package Robots;

import java.awt.Graphics;
import java.util.ArrayList;

import Main.Game;
import Other.Field;
import Units.Robot;
import Units.Unit;
import Units.UnitName;

import jgame.JGObject;
import jgame.JGPoint;
import jgame.JGTimer;

public class Robot1 extends Robot {
	public static int imageHeight = 74, imageWidth = 82;
	
	public final static String stringStandingDown = "robot1_down",
								stringGoDown	   = "robot1animgo_down",
								stringStopDown	   = "robot1animstop_down",
								stringMoveDown	   = "robot1animmove_down";
	
	
	public Robot1(String name, boolean unique, double posX, double posY, int cid){
		super(name, unique, posX, posY, cid, stringStandingDown);
	}
	
	// move methods
	@Override
	public boolean canMove(Field field) {
		if (!Game.board.inBoard(field.i, field.j)) return false;
		if ( UnitName.isRobot(Game.board.getUnitName(field.i, field.j)) ) return false;
		boolean can = false;
		for (int dir=0; dir<Field.adjacentFields.length; dir++) {
			if (field.i == this.getField().i + Field.adjacentFields[dir][0] && field.j == this.getField().j + Field.adjacentFields[dir][1]) can = true;
		}
		return can;
	}
	
	public void paint(){
	//	Game.game.drawImage(getLastX(), getLastY(), "field_mouseover", true);
	}
	
	public void move() {
		
		switch (getState()){
			case 0:
				setGraphic(stringStandingDown);
				break;
			case 1:
				setGraphic(stringGoDown);
				break;
			case 2:
				setGraphic(stringMoveDown);
				JGPoint p = Game.board.getRealCoordinates(getTargetField());
				
				if (Game.board.distance(p, new JGPoint((int)getLastX() + this.imageWidth/2, (int)getLastY() + this.imageHeight/2)) < 5){
					xspeed = yspeed = 0;
					setState(3);
					new JGTimer(5, true){

						@Override
						public void alarm() {
							setState(0);
							Game.board.setAnimation(false);
							Field f = Robot1.this.getField();
							Field t = Robot1.this.getTargetField();
							
							Game.board.moveFromTo(f, t);
							Robot1.this.setField(Robot1.this.getTargetField());
						}						
					};
				}
				break;
			case 3:
				setGraphic(stringStopDown);
				break;
			default: setGraphic(stringStandingDown);
		}		
	}

	@Override
	public ArrayList<Field> whereAttack(Field field) {
		// TODO Auto-generated method stub
		//return null;
		ArrayList<Field> ret = new ArrayList<Field>();
		ret.clear();
		return ret;
	}
	
	@Override
	public boolean canAttack(Field field) {
		// TODO Auto-generated method stub
		return false;
	}
}
